# -*- coding: utf-8 -*-
# @Time : 2021/9/17 20:54
# @Author : hello
# @Email : xxx@gmail.com
# @File : MRSX_ST_FenLei.py
# @Project : mryx_test

"""分类用例"""
import unittest

from page.home_page import HomePage
# from page.fenlei_page import Sorts
from page.sort_page import SortPage
from testcase.base_case import BaseCase
from time import sleep
from appium import webdriver
from utils.swipe import Swipe
from page.shopping_page import Shopping

class FenLei(BaseCase):
    def setUp(self):
        desired_capabilities = {
            "platformName":"Android",
            "deviceName":"127.0.0.1:62025",
            "platformVersion":"5.1.1",
            "appPackage":"cn.missfresh.application",
            "appActivity":"cn.missfresh.module.base.main.view.MainActivity",
            "noReset":"True"
        }
        self.driver= webdriver.Remote("http://localhost:4723/wd/hub", desired_capabilities)
        self.driver.implicitly_wait(30)
        # self.st = Sorts(self.driver)
        self.st=SortPage(self.driver)
        self.sp = Shopping(self.driver)
        self.hp = HomePage(self.driver)
        self.sw=Swipe(self.driver)

    def test_marsx_st_fenlei_001(self):
        """验证每日优鲜-搜索功能"""
        # 进入分类页
        self.hp.click_sort()
        sleep(3)
        # 点击搜索
        self.st.click_search()
        sleep(3)
        # 搜索框输入内容
        self.st.input_keyword("肉")
        sleep(3)
        # 点击搜索
        self.st.click_search_btn()
        sleep(10)
        # 断言
        sd=self.st.dy_search()
        self.assertIn("肉",sd)

    def test_marsx_st_fenlei_002(self):
        """验证每日优鲜-验证删除搜索记录功能"""
        #进入分类页
        self.hp.click_sort()
        sleep(3)
        # 点击搜索
        self.st.click_search()
        sleep(3)
        # 搜索框输入内容
        self.st.input_keyword("肉")
        sleep(4)
        # 点击搜索
        self.st.click_search_btn()
        sleep(3)
        # 返回搜索界面
        self.driver.keyevent(4)
        sleep(3)
        # 点击搜索
        self.st.click_search()
        sleep(3)
        # 点击删除
        self.st.click_sc()
        sleep(3)
        # 确定清空
        self.st.click_qk()
        # 断言
        sd=self.st.dy_lsjl()
        self.assertTrue(sd)

    def test_marsx_st_fenlei_003(self):
        """验证每日优鲜-验证搜索商品添加进购物车后删除功能"""
        # 进入分类页
        self.hp.click_sort()
        sleep(3)
        # 点击搜索
        self.st.click_search()
        sleep(3)
        # 搜索框输入内容
        self.st.input_keyword("肉")
        sleep(3)
        # 点击搜索
        self.st.click_search_btn()
        sleep(7)
        # 点击添加商品数量2次
        for i in range(2):
            self.st.click_fladd()
            sleep(5)
        # 点击购物车
        self.st.click_gwc()
        sleep(3)
        #点击删除
        self.st.click_scsp()
        sleep(3)
        # 确认删除
        self.st.click_scqd()
        sleep(3)
        self.sw.down_swipe()
        sleep(7)
        #断言
        sd=self.st.dy_qksp()
        self.assertTrue(sd)

    def test_marsx_st_fenlei_004(self):
        """每日优鲜-验证商品加入购物车功能"""
        # 点击肉蛋食材
        sleep(30)
        self.hp.click_rdsc()
        sleep(7)
        # # 点击添加2次
        for i in range(2):
            self.st.click_rdscadd()
            sleep(3)
        # # 点击购物车
        self.hp.click_shoppingcat()
        sleep(7)
        # #断言
        sd=self.st.dy_sp()
        self.assertTrue(sd)

    def test_marsx_st_fenlei_005(self):
        """每日优鲜-验证购物车删除功能"""
        # 点击肉蛋食材
        sleep(35)
        self.hp.click_rdsc()
        sleep(5)
        # 点击添加2次
        for i in range(2):
            self.st.click_rdscadd()
            sleep(4)
        # 点击购物车
        self.hp.click_shoppingcat()
        sleep(3)
        # 点击删除
        self.sp.delete2()
        sleep(5)
        # 点击确定
        self.sp.ensure()
        sleep(5)
        # 断言
        sd=self.st.dy_qksp()
        self.assertIn("购物车里空空如也",sd)

if __name__=="__main__":
    unittest.main()